package com.bookm.service;

import com.alibaba.fastjson.JSONObject;

import com.bookm.bean.Book;
import com.bookm.bean.ImportColumnInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;


/**
 * @author xjd
 * @version V1.0.0
 * @Description
 * @date 2022-01-20
 */
/*@Service("BookImportXlsService")
@Scope("prototype")
*/
public class BookImportXlsService extends BaseImportExeclServiceAbsImpl {
    private final Logger logger = LoggerFactory.getLogger(BookImportXlsService.class);

    //    private EmpRptRosterHisService empRptRosterHisService = (EmpRptRosterHisService) SpringContextUtil.getBean("empRptRosterHisService");
//    private EmpRptRosterHisMapper empRptRosterHisMapper = (EmpRptRosterHisMapper)SpringContextUtil.getBean("empRptRosterHisMapper");
//    private PubMethodService pubMethodService = (PubMethodService) SpringContextUtil.getBean("pubMethodService");
    private String currentTableName = "emp_rpt_roster_his";


    // 仅设置导入字段和key 字段
    @Override
    public void setImportColumn(HashMap<String, ImportColumnInfo> icHash) throws Exception {
//		icHash.putAll(pubMethodService.setImportColumn(currentTableName));
        ImportColumnInfo impinfo = null;
//		List<GenColumn> genColumnList = getGenColumnByTabName(tableName);
        impinfo = new ImportColumnInfo();
        impinfo.ici_column = "type";
        impinfo.ici_xls_title = "type";
        impinfo.ici_xls_type = "String";
        icHash.put(impinfo.ici_column, impinfo);

        impinfo = new ImportColumnInfo();
        impinfo.ici_column = "name";
        impinfo.ici_xls_title = "name";
        impinfo.ici_xls_type = "String";
        icHash.put(impinfo.ici_column, impinfo);
    }

    @Override
    public Object formatObject(JSONObject jsonObject) throws Exception {
        // 用于主键检查的对象，仅设置主键重复检查的字段
        Book empRptRosterHis = JSONObject.toJavaObject(jsonObject, Book.class);
        if ("ss".equals(empRptRosterHis.getName())) throw new Exception("姓名不能为ss");
        System.out.println("生成的对象是" + empRptRosterHis);
        return empRptRosterHis;
    }

    // 导入前置处理
    @Override
    public void importBefore() {

    }

    // 导入后置处理
    @Override
    public void importAfter() {
    }

    // 导入特殊检查，如果出现，导入则直接终止
    @Override
    public void import_check(Object object) throws Exception {
    }

    // 导入一条数据
    @Override
    public void importData(Object obj) throws Exception {
        // 用于主键检查的对象，仅设置主键重复检查的字段
        Book objInfo = (Book) obj;
        //判断唯一性
        System.out.println("导入的对象是" + objInfo);
    }

    @Override
    public void setImpflag() {

    }
}